<template>
  <div>

    <el-table
      :data="tableData"
      border
      :height="$store.state.app.tableHeight"
      style="width: 100%; font-size:12px"
    >
      <el-table-column
        prop="name"
        label="用户名"
        width="180"
        align="center"
      />
      <el-table-column
        prop="user_name"
        label="登录账号"
        width="180"
        align="center"
      />
      <el-table-column
        label="状态"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.row.status === "1" ? "正常" : "异常" }}
        </template>
      </el-table-column>
      <el-table-column label="记录" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="handleCheck(scope.row)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click="handleReset(scope.row)">修改</el-button>
          <del-confirm btn-text="删除" :title="`是否确认删除用户名为 “${scope.row.name}” 的用户？`" @onConfirm="delFun(scope.row)" />
          <el-button type="text" size="mini" @click="handleResetPassword(scope.row)">重置密码</el-button>
        </template></el-table-column>
    </el-table>
    <handle-reset ref="reset" @reloadFun="reloadFun" />
    <reset-password ref="passwordReset" @reloadFun="reloadFun" />
  </div>
</template>

<script>
import delConfirm from '@/components/DelConfirm'
import handleReset from './reset-user-info'
import resetPassword from './password-reset'
import { operationSacanningGunUsersApi } from '@/api/system'
export default {
  components: {
    delConfirm,
    handleReset,
    resetPassword
  },
  props: {
    tableData: {
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    return {

    }
  },
  methods: {
    handleCheck(row) {
      console.log(row)
    },
    delFun(row) {
      const data = {
        type: 3,
        id: row.id
      }
      operationSacanningGunUsersApi(data).then(res => {
        if (res.code === 200) {
          this.$message.success('用户删除成功！')
          this.$emit('reloadFun')
        }
      })
    },
    handleReset(row) {
      this.$refs['reset'].dialogFormVisible = true
      this.$refs['reset'].form.name = JSON.parse(JSON.stringify(row.name))
      this.$refs['reset'].form.user_name = JSON.parse(JSON.stringify(row.user_name))
      this.$refs['reset'].form.id = row.id
    },
    handleResetPassword(row) {
      this.$refs['passwordReset'].dialogFormVisible = true
      this.$refs['passwordReset'].form.id = row.id
    },
    reloadFun() {
      this.$emit('reloadFun')
    }
  }
}
</script>

<style lang="sass" scoped>

</style>
